/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import Entity.CTBaoCaoCongNo;
import Util.DatabaseHandle;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Dark_Knight
 */
public class CTBaoCaoCongNoImpl implements CTBaoCaoCongNoDAO {

    public boolean add(CTBaoCaoCongNo data) {
        String sql = "{ call sp_CT_BAOCAOCONGNO_add(?,?,?,?,?)}";
        DatabaseHandle db = new DatabaseHandle(sql, true);
        
        try {            
            db.setParameter(1, data.getMaBaoCaoNo());
            db.setParameter(2, data.getMaKH());
            db.setParameter(3, data.getNoDau());
            db.setParameter(4, data.getPhatSinh());
            db.setParameter(5, data.getNoCuoi());
            db.executeStorePro();
            db.closed();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(CTBaoCaoCongNoImpl.class.getName()).log(Level.SEVERE, null, ex);
            db.closed();
            return false;
        }
    }

    public boolean delete(int MaCTBCCN, int MaKH) {
        String sql = "{ call sp_CT_BAOCAOCONGNO_delete(?,?) }";
        DatabaseHandle db = new DatabaseHandle(sql, true);
        
        try {
            db.setParameter(1, MaCTBCCN);
            db.setParameter(2, MaKH);
            db.executeStorePro();
            db.closed();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(CTBaoCaoCongNoImpl.class.getName()).log(Level.SEVERE, null, ex);
            db.closed();
            return false;
        }
    }

    public boolean edit(CTBaoCaoCongNo data) {
        String sql = "{ call sp_CT_BAOCAOCONGNO_edit(?,?,?,?,?,?) }";
        DatabaseHandle db = new DatabaseHandle(sql, true);
        
        try {
            db.setParameter(1, data.getMaCTBCCN());
            db.setParameter(2, data.getMaBaoCaoNo());
            db.setParameter(3, data.getMaKH());
            db.setParameter(4, data.getNoDau());
            db.setParameter(5, data.getPhatSinh());
            db.setParameter(6, data.getNoCuoi());
            db.executeStorePro();
            db.closed();
            return true;
        } catch (SQLException ex) {
            db.closed();
            return false;
        }
    }

    public ResultSet getAll(int maBaoCao) {
        String sql = "{call sp_CT_BAOCAOCONGNO_getByMaBaoCao(?)}";
        DatabaseHandle db = new DatabaseHandle(sql, false);
        try {
            db.setParameter(1, maBaoCao);
            return db.excuteQuery();
        } catch (SQLException ex) {
            Logger.getLogger(CTBaoCaoCongNoImpl.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
        
    }
    
}
